<template>
  <div class="login-wrap">
    <div class="logo">LG Display</div>
    <div class="login-contain">
      <div class="login-content">
        <div class="login-main">
          <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" status-icon>
            <el-form-item >
              <div class="cake">
                <img width="60px" src="~@/assets/img/cake.png">
              </div>
            </el-form-item>
            <el-form-item>
              <img src="~@/assets/img/log_title.png" style="width:100%">
            </el-form-item>
            <el-form-item class="input-form">
              <div class="input">
                <img src="~@/assets/img/phone.png">
                <el-input v-model="dataForm.userName" placeholder="请输入手机号"></el-input>
              </div>
            </el-form-item>
            <el-form-item class="input-form" prop="password">
              <div class="input">
                <img src="~@/assets/img/pwd.png">
                <el-input v-model="dataForm.password" type="password" placeholder="请输入登录密码"></el-input>
              </div>
            </el-form-item>
            <!-- <el-form-item prop="captcha" class="input-form"> -->
            <!-- <el-row :gutter="20">
              <el-col :span="14">
                <el-input v-model="dataForm.captcha" placeholder="验证码">
                </el-input>
              </el-col>
              <el-col :span="10" class="login-captcha">
                <img :src="captchaPath" @click="getCaptcha()" alt="">
              </el-col>
            </el-row> -->
          <!-- </el-form-item> -->
            <el-form-item>
              <el-button class="login-btn-submit" type="primary" @click="dataFormSubmit()">登录</el-button>
            </el-form-item>
          </el-form>
        </div>
        <div class="right">
          <img width="100%" src="~@/assets/img/loginpeople.png">
        </div>
      </div>
    </div>
    <div class="bottom">@LGD 乐金显示（南京）有限公司 版权所有 苏ICP备11085809号</div>
  </div>
</template>

<script>
import { getUUID } from '@/utils'
export default {
  data() {
    return {
      dataForm: {
        userName: '',
        password: '',
        uuid: '',
        captcha: ''
      },
      dataRule: {
        userName: [{ required: true, message: '帐号不能为空', trigger: 'blur' }],
        password: [{ required: true, message: '密码不能为空', trigger: 'blur' }],
        captcha: [{ required: true, message: '验证码不能为空', trigger: 'blur' }]
      },
      captchaPath: ''
    }
  },
  created() {
    this.getCaptcha()
  },
  methods: {
    // 提交表单
    dataFormSubmit() {
        // this.$cookie.set('token', '4d96980e7c471e419c1d09da32dbc912')
        // this.$router.replace({ name: 'home' })
        // return

      this.$refs['dataForm'].validate(valid => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl('/sys/login'),
            method: 'post',
            data: this.$http.adornData({
              username: this.dataForm.userName,
              password: this.dataForm.password,
              uuid: this.dataForm.uuid,
              captcha: this.dataForm.captcha
            })
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.$cookie.set('token', data.token)
              this.$router.replace({ name: 'home' })
            } else {
              this.getCaptcha()
              this.$message.error(data.msg)
            }
          })
        }
      })
    },
    // 获取验证码
    getCaptcha() {
      this.dataForm.uuid = getUUID()
      this.captchaPath = this.$http.adornUrl(`/captcha.jpg?uuid=${this.dataForm.uuid}`)
    }
  }
}
</script>

<style lang="scss" scoped>
.login-wrap {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url(~@/assets/img/bg.png);
  background-size:100% 100%;

  .logo{
    margin-left: 48px;
    margin-top: 32px;
    color: #fff;
    font-size: 18px;
    font-weight: 600;
  }

  .login-contain{
    width: 100%;
    height: 80%;
    display: flex;
    justify-content: center;//使子项目水平居中
    align-items: center;//使子项目垂直居中
  }

  .login-content{
    display: flex;
    justify-content: center;
    align-items: center;//使子项目垂直居中

    // 左边
    .login-main {
      width: 450px;
      padding: 30px;
      text-align: center;

      .cake{
        margin: 0 auto;
        padding: 10px;
        width: 80px;
        height: 80px;
        background: #fff;
        border-radius: 20px;
      }

      .login-title {
        color:#fff;
      }
      .input-form{
        margin:  28px auto;
        width: 260px;
      }
      .input {
        background:rgb(57, 154, 231);
        // opacity: 0.8;
        height: 40px;
        width: 100%;
        border-radius: 20px;
        display: inline-flex;
      }
      .input img{
        margin-left: 15px;
        margin-right: -30px;
        margin-top: 10px;
        width: 20px;
        height: 20px;
      }
      .input /deep/ .el-input__inner {
        background:rgb(57, 154, 231);
        // opacity: 0.8;
        width: 200px;
        height: 40px;
        border:0px solid #fff;
        color: #fff;
      }
      .login-btn-submit {
        width: 40%;
        height: 40px;
        border-radius: 20px;
        border:1px solid #fff;
        margin-top: 20px;
        background-color:#3399FF;
      }
      .login-captcha {
        overflow: hidden;
        > img {
          width: 100%;
          cursor: pointer;
        }
      }
    }

    // 右边
    .right{
      margin-left: 80px;
      width: 500px;
      display: flex;
      align-items: center;
    }
  }
  .bottom{
    position: fixed;
    width: 100%;
    text-align: center;
    bottom: 30px;
    color: #FFFFFF;
  }
}
</style>
